package com.ys.filter_interceptor.filter;

import com.ys.filter_interceptor.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @program: filter_interceptor
 * @description: 自定义filter
 * @author: Henry
 * @create 2020-06-09 19:11
 **/
@Component
public class MyFilter implements Filter {

    @Autowired
    private TestService testService;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter 前置");
    }

    @Override
    public void destroy() {
        System.out.println("Filter 后置");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        System.out.println("Filter 处理中");
        testService.a();
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
